cdGOPATH:=$(shell go env GOPATH)
OBJECTDIR:=$(shell pwd)
GIT_COMMIT=$(shell git rev-parse --short HEAD)
GIT_TAG=$(shell git describe --abbrev=0 --tags --always --match "v*")
# IMAGE_TAG=$(GIT_TAG)-$(GIT_COMMIT)
IMAGE_TAG = 0.0.1
IMAGE_NAME = welfare
NETWORK = micro-welfare
MICRO_REGISTER = mdns
CFG_CLUSTER = prod


.PHONY: proto
proto:
	@echo execute ${PROTO} proto file generate ${OBJECTDIR}
	protoc --proto_path=. --proto_path=${GOPATH}/src --proto_path=. --micro_out=. --go_out=. common/proto/${PROTO}/${PROTO}.proto
	mv -if github.com/xionglongjun/welfare/common/proto/${PROTO}/* common/proto/${PROTO}
	rm -rf e.coding.net/
frpc:
	docker run --rm --network host -d -v ${OBJECTDIR}/frp/frpc.ini:/etc/frp/frpc.ini --name locl_frpc snowdreamtech/frpc
# 内网映射
docker-frpc:
	# docker stop frpc
	# --restart=always
	docker run --rm --network ${NETWORK} -d -v ${OBJECTDIR}/frp/frpc.ini:/etc/frp/frpc.ini --name frpc snowdreamtech/frpc
# 对外无插件api服务
micro-api:
	docker run --rm --name welfare-api -d -p 8080:8080 --network ${NETWORK} -e MICRO_REGISTER=mdns micro/micro api --handler=rpc --address=:8080
# 对外web服务
micro-web:
	docker run --rm --name welfare-web -d -p 8082:8082 --network ${NETWORK} micro/micro web  --address=:8082
# welfare 项目 docker 网络服务
network:
	docker network create -d bridge ${NETWORK}

# 接口文档
swagger:
	docker run --rm --name swagger-ui -d -p 8090:8080 -e SWAGGER_JSON=/swagger/swagger.json -v ${OBJECTDIR}/docs:/swagger swaggerapi/swagger-ui:latest
build-micro:
	docker build -f micro/Dockerfile . -t $(IMAGE_NAME)/micro:latest
# welfare 项目 web 对外服务
web:
	docker run --rm --name welfare-web -d -p 8021:8081 --network ${NETWORK} -e MICRO_REGISTER=${MICRO_REGISTER} ${IMAGE_NAME}/micro:latest --cors-allowed-headers="Content-Type,Authorization,Client-Type" --cors-allowed-origins="*" --cors-allowed-methods="OPTIONS,DELETE,GET,POST,PUT" --enable_stats web
# welfare 项目有插件 api 对外服务
api:
	docker run --rm --name welfare-api -d -p 8020:8080 --network ${NETWORK} -e MICRO_REGISTER=${MICRO_REGISTER} ${IMAGE_NAME}/micro:latest --cors-allowed-headers="Content-Type,Authorization,Client-Type" --cors-allowed-origins="*" --cors-allowed-methods="OPTIONS,DELETE,GET,POST,PUT" --enable_stats api --handler=api
# welfare api 的 http接口方式（目前主要用于图片上传接口）
api-http:
	docker run --rm --name welfare-api-http -d -p 8022:8080 --network ${NETWORK} -e MICRO_REGISTER=${MICRO_REGISTER} ${IMAGE_NAME}/micro:latest--cors-allowed-headers="Content-Type,Authorization,Client-Type" --cors-allowed-origins="*" --cors-allowed-methods="OPTIONS,DELETE,GET,POST,PUT" --enable_stats api --handler=http
# 图片上传服务 handler=http
upload-api-http:
	docker build -f upload/api-http/Dockerfile . -t $(IMAGE_NAME)/upload-api-http:$(IMAGE_TAG)
	docker run --rm --name welfare-upload-api-http -d -p :50051 --network ${NETWORK} -e CFG_CLUSTER=${CFG_CLUSTER} -e MICRO_ADDRESS=:50051 -e MICRO_REGISTRY=${MICRO_REGISTER} $(IMAGE_NAME)/upload-api-http:${IMAGE_TAG}
# 短信服务接口
sms-api:
	docker build -f sms/api/Dockerfile . -t $(IMAGE_NAME)/sms-api:$(IMAGE_TAG)
	docker run --rm --name welfare-sms-api -d -p :50051 --network ${NETWORK} -e CFG_CLUSTER=${CFG_CLUSTER} -e MICRO_ADDRESS=:50051 -e MICRO_REGISTRY=${MICRO_REGISTER} $(IMAGE_NAME)/sms-api:${IMAGE_TAG}
# 短信服务
sms-srv:
	docker build -f sms/srv/Dockerfile . -t $(IMAGE_NAME)/sms-srv:$(IMAGE_TAG)
	docker run --rm --name welfare-sms-srv -d -p :50051 --network ${NETWORK} -e CFG_CLUSTER=${CFG_CLUSTER} -e MICRO_ADDRESS=:50051 -e MICRO_REGISTRY=${MICRO_REGISTER} $(IMAGE_NAME)/sms-srv:${IMAGE_TAG}
# 用户服务
user-srv:
	docker build -f user/srv/Dockerfile . -t $(IMAGE_NAME)/user-srv:$(IMAGE_TAG)
	docker run --rm --name welfare-user-srv -d -p :50051 --network ${NETWORK} -e CFG_CLUSTER=${CFG_CLUSTER} -e MICRO_ADDRESS=:50051 -e MICRO_REGISTRY=${MICRO_REGISTER} $(IMAGE_NAME)/user-srv:${IMAGE_TAG}
# 账户服务
account-srv:
	docker build -f account/srv/Dockerfile . -t $(IMAGE_NAME)/account-srv:$(IMAGE_TAG)
	docker run --rm --name welfare-account-srv -d -p :50051 --network ${NETWORK} -e CFG_CLUSTER=${CFG_CLUSTER} -e MICRO_ADDRESS=:50051 -e MICRO_REGISTRY=${MICRO_REGISTER} $(IMAGE_NAME)/account-srv:${IMAGE_TAG}
# 申述服务
appeal-srv:
	docker build -f account/srv/Dockerfile . -t $(IMAGE_NAME)/appeal-srv:$(IMAGE_TAG)
	docker run --rm --name welfare-appeal-srv -d -p :50051 --network ${NETWORK} -e CFG_CLUSTER=${CFG_CLUSTER} -e MICRO_ADDRESS=:50051 -e MICRO_REGISTRY=${MICRO_REGISTER} $(IMAGE_NAME)/appeal-srv:${IMAGE_TAG}
# 接口服务
gateway-api:
	docker build -f gateway/api/Dockerfile . -t $(IMAGE_NAME)/gateway-api:$(IMAGE_TAG)
	docker run --rm --name welfare-gateway-api -d -p :50051 --network ${NETWORK} -e CFG_CLUSTER=${CFG_CLUSTER} -e MICRO_ADDRESS=:50051 -e MICRO_REGISTRY=${MICRO_REGISTER} $(IMAGE_NAME)/gateway-api:${IMAGE_TAG}
# 后台接口服务
gateway-backoffice:
	docker build -f gateway/api/Dockerfile . -t $(IMAGE_NAME)/gateway-backoffice:$(IMAGE_TAG)
	docker run --rm --name welfare-gateway-backoffice -d -p :50051 --network ${NETWORK} -e CFG_CLUSTER=${CFG_CLUSTER} -e MICRO_ADDRESS=:50051 -e MICRO_REGISTRY=${MICRO_REGISTER} $(IMAGE_NAME)/gateway-backoffice:${IMAGE_TAG}
PHONY: frpc docker-frpc micro-api micro-web api user-srv user-api